<?php
// +----------------------------------------------------------------------
// | When work is a pleasure, life is a joy!
// +----------------------------------------------------------------------
// |User: ShouKun Liu  |  Email:24147287@qq.com  | Time:2017/8/20 15:26
// +----------------------------------------------------------------------
// | TITLE: 账单表
// +----------------------------------------------------------------------


namespace Common\Model;


use Think\Model;

class AccountModel extends Model
{

    /**
     * 获取可用账号
     */
    public function getAccountList()
    {
        $where['count'] = array('>', 0);
        $where['status'] = 1;
        $where['is_delete'] = 0;
        return $this->where($where)->select();
    }

    /**
     * 开启
     * @param $id
     * @param string $user
     * @return bool
     */
    public function openAccount($id,$user=' ')
    {

        $this->where(['id' => $id])->save(['status' => 2,'user'=>$user]);
        return $this->where(['id' => $id])->setDec('count');
    }

    /**
     * 关闭账号
     * @param $id
     * @param string $user
     * @return bool
     */
    public function closeAccount($id,$user=' ')
    {
        return $this->where(['id' => $id])->save(['status' => 1,'user'=>$user]);
    }

    /**
     * 初始化账户
     * @return bool
     */
    public function initAccount()
    {
        $data['count'] = 5;
        $data['status'] = 1;
        return $this->where(['is_delete' => 0])->save($data);
    }


}